<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <div class="seacrhMoney">
        <el-form-item>
          <div class="balance-searchMoney">
            订单编号
            <el-input class="input" v-model="dataForm.userName" placeholder="请输入订单编号"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            支付单号
            <el-input class="input" v-model="paySerialId" placeholder="请输入支付单号"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            支付时间
            <el-date-picker v-model="value" :default-time="['00:00:00', '23:59:59']" :clearable='false' type="daterange" value-format="yyyy-MM-dd HH:mm:ss" style="width:240px" class="input" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            订单类型
            <el-select v-model="ordertype" filterable placeholder="请选择">
              <el-option v-for="item in options2" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            支付方式
            <el-select v-model="value2" filterable placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            结算状态
            <el-select v-model="settlement" filterable placeholder="请选择">
              <el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            收费单位
            <el-select v-model="legalAccountCodes" filterable placeholder="请选择">
              <el-option v-for="item in charges" :key="item.legalAccountCode" :label="item.legalCompanyName" :value="item.legalAccountCode">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            用户地址
            <el-input class="input" v-model="communityInfos" placeholder="请输入用户地址"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="demand">查询</el-button>
          <el-button type="primary" @click="empty">清空</el-button>
        </el-form-item>
      </div>
    </el-form>

    <!-- 表格 -->
    <div class="export">
      <div style="display: flex; justify-content: flex-end;margin-bottom:10px;">
        <el-button type="primary" @click="exportExcel()">导出Excel</el-button>
      </div>
      <el-table :data="dataList" v-loading="dataListLoading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-custom-class="loading_color" style="width: 100%;">
        <template slot="empty">
          <img class="machine" src="../../assets/img/machine.svg" alt="" />
          <div style="font-size: 14px; text-align: center">暂无数据</div>
        </template>
        <!-- <el-table-column prop="paySerialNbr" width="130" header-align="center" align="center" label="四格缴费编号" :render-header="fourGrid">
        </el-table-column> -->
        <!-- <el-table-column prop="" width="100" header-align="center" align="center" label="订单类型" :render-header="renderHeader">
        </el-table-column>  -->
        <!-- <el-table-column prop="totalFee" width="100" header-align="center" align="center" label="账单金额(元)">
        </el-table-column> -->
        <!-- <el-table-column prop="endBillCycle" header-align="center" align="center" label="账单月份" width="140">
          <template slot-scope="scope">
            {{ scope.row.startBillCycle }} -
            {{ scope.row.endBillCycle }}
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="" width="130" header-align="center" align="center" label="订单联系人">
          <template slot-scope="scope">
            <div size="small" type="danger">
              {{ scope.row.memberName }} /
              {{ scope.row.memberPhone }}
            </div>
          </template>
        </el-table-column> -->
        <el-table-column prop="orderNo" width="120" header-align="center" align="center" label="订单编号">
          <template slot-scope="scope">
            <div size="small" type="danger">
              <div v-if="scope.row.billType == 1" size="small">{{scope.row.paySerialNbr}}</div>
              <div v-if="scope.row.billType == 3" size="small">{{ scope.row.orderNo}}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="paySerialId" header-align="center" align="center" label="支付单号" width="100">
        </el-table-column>
        <el-table-column prop="" width="100" header-align="center" align="center" label="订单类型">
          <template slot-scope="scope">
            <div size="small" type="danger">
              <div v-if="scope.row.billType == 1" size="small">物业费</div>
              <div v-if="scope.row.billType == 2" size="small">有偿工单</div>
              <div v-if="scope.row.billType == 3" size="small">到家服务</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="dealType" header-align="center" align="center" label="交易类型" width='100'>
          <template slot-scope="scope">
            <div v-if="scope.row.dealType == 0" size="small">收款</div>
            <div v-if="scope.row.dealType == 1" size="small">退款</div>
          </template>
        </el-table-column>
        <el-table-column prop="dealDes" width="100" header-align="center" align="center" label="交易描述">
        </el-table-column>
        <!-- <el-table-column prop="endBillCycle" header-align="center" align="center" label="交易时间" width="140">
          <template slot-scope="scope">
            <div v-if="scope.row.billType != 3" size="small">{{ scope.row.startBillCycle }} -{{ scope.row.endBillCycle }} </div>
            <div v-if="scope.row.billType == 3" size="small">{{ scope.row.paymentTime }} </div>
          </template>
        </el-table-column> -->
        <el-table-column prop="paymentFee" width="100" header-align="center" align="center" label="交易金额(元)">
          <template slot-scope="scope">
            <div>{{ scope.row.paymentFee| MoneyFormat}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="paymentMethod" header-align="center" align="center" label="支付方式">
          <template slot-scope="scope">
            <div v-if="scope.row.paymentMethod == 1" size="small">微信</div>
            <div v-if="scope.row.paymentMethod == 2" size="small">支付宝</div>
            <div v-if="scope.row.paymentMethod == 3" size="small">云闪付</div>
            <div v-if="scope.row.paymentMethod == 4" size="small">快捷支付</div>
          </template>
        </el-table-column>
        <el-table-column prop="paymentTime" header-align="center" width="100" align="center" label="支付时间">
        </el-table-column>
        <el-table-column prop="platformType" header-align="center" align="center" label="支付终端">
        </el-table-column>
        <el-table-column prop="legalCompanyName" header-align="center" align="center" label="收费单位" width="100">
        </el-table-column>
        <el-table-column prop="userAddress" header-align="center" align="center" label="用户地址">
        </el-table-column>
        <el-table-column prop="settlementStatus" header-align="center" align="center" label="结算状态">
          <template slot-scope="scope">
            <div v-if="scope.row.settlementStatus === 0" size="small" type="danger" class="blueMoney">
              未结算
            </div>
            <div v-else size="small" class="greenMoney">已结算</div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        userName: "",
      },
      options: [
        {
          value: "1",
          label: "微信",
        },
        {
          value: "2",
          label: "支付宝",
        },
        {
          value: "3",
          label: "云闪付",
        },
        {
          value: "4",
          label: "快捷支付",
        },
      ],
      options1: [
        {
          value: "0",
          label: "未结算",
        },
        {
          value: "1",
          label: "已结算",
        },
      ],
      options2: [
        {
          value: "1",
          label: "物业费",
        },
        {
          value: "2",
          label: "有偿工单",
        },
        {
          value: "3",
          label: "到家服务",
        },
      ],
      value4: "",
      dataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      value: "",
      value1: "",
      value2: "",
      value4: "",
      amount: "",
      charges: [],
      settlement: '',
      legalAccountCodes: '',
      communityInfos: '',
      settlementAmount: "",
      paySerialId: "", // 支付流水号
      payDate: "", // 支付日期，格式：yyyy-MM-dd
      startBillCycle: "", // 账期开始时间，格式：yyyyMMdd
      endBillCycle: "", // 账期结束时间，格式：yyyyMMdd
      paymentMethod: "", // 支付方式：1-微信,2-支付宝,3-云闪付,4-快捷支付
      settlementStatus: "", // 结算状态：0-未结算、1-已结算
      billType: "",
      ordertype: '',
      userCode: "",
      ListData: [],
      communityCode: "",
      platformType: "",
    };
  },
  activated () {
    this.userCode = localStorage.getItem("userCode");
    this.getDataList();
    this.getDataMoney();
    this.subsidiary()
    this.sava()
  },
  methods: {
    // 表格头部提示事件
    renderHeader (h, { column }) {
      return h("span", [
        h("span", column.label),
        h(
          "el-tooltip",
          {
            props: {
              effect: "dark",
              content: "包含物业费和有偿工单",
              placement: "top",
            },
          },
          [
            h("i", {
              class: "el-icon-question",
              style: "color:#000;margin-left:5px;",
            }),
          ],
          {
            content: "包含物业费和有偿工单",
          }
        ),
      ]);
    },
    // 表格头部提示事件
    fourGrid (h, { column }) {
      return h("span", [
        h("span", column.label),
        h(
          "el-tooltip",
          {
            props: {
              effect: "dark",
              content: "四格缴费的唯一编号，可用于跟四格ERP对账",
              placement: "top",
            },
          },
          [
            h("i", {
              class: "el-icon-question",
              style: "color:#000;margin-left:5px;",
            }),
          ],
          {
            content: "四格缴费的唯一编号，可用于跟四格ERP对账",
          }
        ),
      ]);
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/billDetail/detailList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          orderNo: this.orderNo,
          paySerialId: this.paySerialId, // 支付流水号
          payDateEnd: this.value[1],
          payDateStart: this.value[0], // 支付日期，格式：yyyy-MM-dd
          startBillCycle: this.startBillCycle, // 账期开始时间，格式：yyyyMMdd
          endBillCycle: this.endBillCycle, // 账期结束时间，格式：yyyyMMdd
          paymentMethod: this.paymentMethod, // 支付方式：1-微信,2-支付宝,3-云闪付,4-快捷支付
          settlementStatus: this.settlementStatus, // 结算状态：0-未结算、1-已结算
          communityCode: this.communityCode,
          billType: this.billType,
          platformType: this.platformType,
        }),
      }).then(({ data }) => {
        console.log(data)
        if (data.success === 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 获取金额
    getDataMoney () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/billDetail/amountReceived"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          orderNo: this.dataForm.userName,
          paySerialId: this.paySerialId, // 支付流水号
          payDateEnd: this.value[1],
          payDateStart: this.value[0],// 支付日期，格式：yyyy-MM-dd
          startBillCycle: this.startBillCycle, // 账期开始时间，格式：yyyyMMdd
          endBillCycle: this.endBillCycle, // 账期结束时间，格式：yyyyMMdd
          paymentMethod: this.paymentMethod, // 支付方式：1-微信,2-支付宝,3-云闪付,4-快捷支付
          settlementStatus: this.settlementStatus, // 结算状态：0-未结算、1-已结算
          communityCode: this.communityCode,
          billType: this.billType,
        }),
      }).then(({ data }) => {
        if (data.success === 1) {
          this.amount = data.data.amount;
          this.settlementAmount = data.data.settlementAmount;
        } else {
        }
        this.dataListLoading = false;
      });
    },
    //子公司列表
    subsidiary () {
      this.$http({
        url: this.$http.adornUrl(
          "/cassadmin/legalCompany/getByCurrentFinanceCode"
        ),
      }).then(({ data }) => {
        // console.log(data, '子公司列表')
        if (data.success === 1) {
          this.ListData = data.data;
          // console.log(this.ListData)
        } else {
        }
        this.dataListLoading = false;
      });
    },
    //收费单位
    status5 (e) {
      this.pageIndex = 1;
      this.legalAccountCode = e;
      this.getDataList();
      this.getDataMoney();
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/billDetail/detailList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          orderNo: this.dataForm.userName,
          paySerialId: this.paySerialId, // 支付流水号
          payDateEnd: this.value[1],
          payDateStart: this.value[0], // 支付日期，格式：yyyy-MM-dd
          startBillCycle: this.startBillCycle, // 账期开始时间，格式：yyyyMMdd
          endBillCycle: this.endBillCycle, // 账期结束时间，格式：yyyyMMdd
          paymentMethod: this.value2, // 支付方式：1-微信,2-支付宝,3-云闪付,4-快捷支付
          settlementStatus: this.settlement, // 结算状态：0-未结算、1-已结算
          communityCode: this.communityCode,
          billType: this.ordertype,
          platformType: this.platformType,
          legalAccountCode: this.legalAccountCodes,
          userAddress: this.communityInfos
        }),
      }).then(({ data }) => {
        console.log(data)
        if (data.success === 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false
      });
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/billDetail/detailList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          orderNo: this.dataForm.userName,
          paySerialId: this.paySerialId, // 支付流水号
          payDateEnd: this.value[1],
          payDateStart: this.value[0],// 支付日期，格式：yyyy-MM-dd
          startBillCycle: this.startBillCycle, // 账期开始时间，格式：yyyyMMdd
          endBillCycle: this.endBillCycle, // 账期结束时间，格式：yyyyMMdd
          paymentMethod: this.value2, // 支付方式：1-微信,2-支付宝,3-云闪付,4-快捷支付
          settlementStatus: this.settlement, // 结算状态：0-未结算、1-已结算
          communityCode: this.communityCode,
          billType: this.ordertype,
          platformType: this.platformType,
          legalAccountCode: this.legalAccountCodes,
          userAddress: this.communityInfos
        }),
      }).then(({ data }) => {
        console.log(data)
        if (data.success === 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false
      });
    },
    //查询
    demand () {
      this.pageIndex = 1
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/billDetail/detailList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          orderNo: this.dataForm.userName,
          paySerialId: this.paySerialId, // 支付流水号
          payDateEnd: this.value[1],
          payDateStart: this.value[0], // 支付日期，格式：yyyy-MM-dd
          startBillCycle: this.startBillCycle, // 账期开始时间，格式：yyyyMMdd
          endBillCycle: this.endBillCycle, // 账期结束时间，格式：yyyyMMdd
          paymentMethod: this.value2, // 支付方式：1-微信,2-支付宝,3-云闪付,4-快捷支付
          settlementStatus: this.settlement, // 结算状态：0-未结算、1-已结算
          communityCode: this.communityCode,
          billType: this.ordertype,
          platformType: this.platformType,
          legalAccountCode: this.legalAccountCodes,
          userAddress: this.communityInfos
        }),
      }).then(({ data }) => {
        console.log(data)
        if (data.success === 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false
      });
    },
    //清空
    empty () {
      this.dataForm.userName = ''
      this.value = ''
      this.value1 = ''
      this.value2 = ''
      this.value3 = ''
      this.payDate = ''
      this.settlement = ''
      this.ordertype = ''
      this.paySerialId = ''
      this.legalAccountCodes = ''
      this.dataForm.communityInfos = ''
      this.communityInfos = ''
      this.getDataList()
    },
    //收费单位下拉
    sava () {
      this.$http({
        url: this.$http.adornUrl("/cassadmin/v1/billDetail/fetchAllLegalCompany"),
        method: "get",
      }).then(({ data }) => {
        console.log(data, '213123')
        this.charges = data.data
      });
    },
    // 导出excel
    exportExcel () {
      if (this.value == '') {
        var end = this.value
        var start = this.value
      } else {
        var end = this.value[1]
        var start = this.value[0]
      }
      window.location.href =
        `https://api.xstarlife.com/cassadmin/v1/billDetail/downloadDetailList?userType=2&billType=${this.ordertype}&paySerialId=${this.paySerialId}&settlementStatus=${this.settlement}&payDateStart=${start}&payDateEnd=${end}&platformType=${this.platformType}&communityCode=${this.communityCode}&legalAccountCode=${this.userCode}&endBillCycle=${this.endBillCycle}&orderNo=${this.dataForm.userName}&startBillCycle=${this.startBillCycle}&paymentMethod=${this.value2}&userAddress=${this.communityInfos}&chargingUnit=${this.legalAccountCodes}`
    },
  },
};
</script>
<style scoped>
.balance-searchMoney {
  display: flex;
  align-items: center;
}
.input {
  flex: 1;
  margin-left: 5px;
}
.nav {
  margin-top: 28px;
  display: flex;

  margin-bottom: 50px;
}
.money {
  width: 200px;
  height: 100px;
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
  margin-right: 30px;
}
.money div {
  text-align: center;
  color: #333;
}
.one {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
}
.two {
  font-size: 14px;
}
.m20 {
  margin-left: 60px;
}
.export {
  margin-top: 30px;
  background-color: #fff;
  padding: 20px;
  border-radius: 6px;
}
</style>
